home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / MDISAMP.PAK / DLWRAP.H next >
C/C++ Source or Header  |  1997-05-06  |  2KB  |  84 lines

  1.  
  2. #define CN_BASE 0xBC00 // from CONTROLS.PAS
  3.  
  4. typedef HWND (__stdcall *TWindowFactoryFunc)(HWND hwndParent, LPUNKNOWN &pObj);
  5.  
  6. #ifdef OWL_WINDOW_H
  7.  
  8. class TDelphiFormWrapper: public TWindow
  9. {
  10. public:
  11.   TDelphiFormWrapper(TWindowFactoryFunc factoryFunc,
  12.       TWindow* parent, const char far* title = 0, TModule* module = 0)
  13.       : TWindow( parent, title, module ), Factory(factoryFunc), pOleObj(0) { }
  14.  
  15. protected:
  16.   bool PreProcessMsg( MSG &msg ) {
  17.     // duplicates the code in FORMS.PAS for IsKeyMsg()
  18.     if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST) &&
  19.       (GetCapture() == 0)) {
  20.       if (SendMessage(CN_BASE + msg.message, msg.wParam, msg.lParam) != 0 )
  21.         return true;
  22.     }
  23.     if (IsDialogMessage( GetHandle(), &msg ))
  24.         return true;
  25.     return false;
  26.   }
  27.   bool Register() { return true; } // don't bother, Delphi will do this
  28.   void PerformCreate(int menuOrId) {
  29.       LPUNKNOWN pObj;
  30.       SetHandle(Factory(Parent->GetHandle(), pObj));
  31.   }
  32. public:
  33.   LPUNKNOWN pOleObj;
  34. private:
  35.   TWindowFactoryFunc Factory;
  36. };
  37.  
  38.  
  39.  
  40. #endif
  41.  
  42. #ifdef __AFXWIN_H__
  43.  
  44. class CDelphiFormWrapper: public CView
  45. {
  46. public:
  47.   CDelphiFormWrapper(TWindowFactoryFunc factoryFunc)
  48.       : Factory(factoryFunc), pOleObj(0) { }
  49.  
  50. protected:
  51.   BOOL PreTranslateMessage(LPMSG lpMsg) {
  52.     // duplicates the code in FORMS.PAS for IsKeyMsg()
  53.     if (m_hWnd && (lpMsg->message >= WM_KEYFIRST) && (lpMsg->message <= WM_KEYLAST) &&
  54.       (::GetCapture() == 0)) {
  55.       if (SendMessage(CN_BASE + lpMsg->message, lpMsg->wParam, lpMsg->lParam) != 0 )
  56.         return true;
  57.     }
  58.     return CWnd::PreTranslateMessage(lpMsg);
  59.   }
  60.   virtual void OnDraw(CDC *)
  61.   {
  62.     // do nothing; we should never be called.
  63.   }
  64.  
  65. public:
  66.   // for child windows, views, panes etc
  67.   BOOL Create(CWnd *pParentWnd)
  68.   {
  69.       Attach( Factory(pParentWnd->m_hWnd, pOleObj) );
  70.       return m_hWnd != NULL;
  71.   }
  72.   afx_msg void OnPaint()
  73.   {
  74.     // don't do CView::OnPaint, we are a control!
  75.     Default();
  76.   }
  77.  
  78. public:
  79.   LPUNKNOWN pOleObj;
  80. private:
  81.   TWindowFactoryFunc Factory;
  82. };
  83.  
  84. #endif